package com.ht.medicaltreatment.viewmodel

import androidx.lifecycle.viewModelScope
import com.ht.medicaltreatment.bean.CentrifugeSample
import com.xgst.lib.http.ApiResult
import kotlinx.coroutines.launch

class CentrifugeDetailViewModel : BaseViewModel() {
    //批量删除离心详情中的样本
    fun deleteSample(centrifugeSampleIdList :String,onSuccess:()->Unit, onError:(String)->Unit){
        viewModelScope.launch {
            val bean = mApi.deleteSample(centrifugeSampleIdList)
            when(bean){
                is ApiResult.Success -> onSuccess()
                is ApiResult.Error -> onError(bean.errorMessage)
            }
        }
    }

    //根据离心机id查询当前离心的样本以及是否离心完成等
    fun centrifugeInfo(id:String, onSuccess:(MutableList<CentrifugeSample>?)->Unit, onError:(String)->Unit){
        viewModelScope.launch {
            val bean = mApi.centrifugeInfo(id)
            when(bean){
                is ApiResult.Success -> onSuccess(bean.data.data?.centrifugeSampleList)
                is ApiResult.Error -> onError(bean.errorMessage)
            }
        }
    }
}
